from bewilder import builder, text, elements

elements.create(globals(), 'h1 div p ul li')
el = elements

class BaseView(object):
    stylesheet = 'body {background:#ddd; color:black; font-family:Georgia}'
    
    @builder
    def render(self):
        with el.head:
            with el.style(type='text/css'):
                text(self.stylesheet, escape=False)
            
            with el.title:
                self.title()
        
        with el.body:
            with h1(style='font-size:200%'):
                self.title()
        
            with div(class_='content'):
                self.content()

class FavoriteView(BaseView):
    def __init__(self, things):
        self.things = things
        
    def title(self):
        text('Favorite Things')
    
    def content(self):
        with p(style='color:green')('These are a few'):
            text('of my favorite things.')
    
        with ul:
            for thing in self.things:
                li(thing)


def main():
    favs = ['Raindrops on roses.',
            'Whiskers on kittens.',
            'Bright copper kettles',
            'Warm woolen mittens.',
            'Brown paper packages tied up with strings.']
    return FavoriteView(favs).render()

if __name__ == '__main__':
    print main()